﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using GreatB2C.Config.SiteInfo;

namespace GreatB2C.Web.Manage.SystemSet.SiteInfo
{
    public partial class ThumbnailSet : Inherit.ManagePage
    {
        protected void Page_Load( object sender , EventArgs e )
        {
            if ( !IsPostBack )
            {
                LoadSetting( );
            }
        }

        protected void LoadSetting( )
        {
            txtThumbsWidth.Text = ThumbnailConfig.ThumbsWidth.ToString( );
            txtThumbsHeight.Text = ThumbnailConfig.ThumbsHeight.ToString( );
            radThumbsMode.SelectedValue = ThumbnailConfig.ThumbsMode.ToString( );
            txtBgColor.Value = ThumbnailConfig.BgColor.ToString( );
            if ( ThumbnailConfig.WaterMarkType.ToString( ) == "0" )
            {
                radText.Checked = true;
                radImage.Checked = false;
                TextWaterMark.Style[ "display" ] = "block";
                PicWaterMark.Style[ "display" ] = "none";
            }
            else if ( ThumbnailConfig.WaterMarkType.ToString( ) == "1" )
            {
                radText.Checked = false;
                radImage.Checked = true;
                TextWaterMark.Style[ "display" ] = "none";
                PicWaterMark.Style[ "display" ] = "block";
            }
            txtWaterMarkText.Text = ThumbnailConfig.WaterMarkText.ToString( );
            ddlWaterMarkTextFoneType.SelectedValue = ThumbnailConfig.WaterMarkTextFoneSize.ToString( );
            DropWaterMarkTextFoneStyle.SelectedValue = ThumbnailConfig.WaterMarkTextFoneStyle.ToString( );
            txtWaterMarkTextFoneSize.Text = ThumbnailConfig.WaterMarkTextFoneSize.ToString( );
            txtWaterMarkTextFoneColor.Value = ThumbnailConfig.WaterMarkTextFoneColor.ToString( );
            txtWaterMarkTextFoneBorder.Text = ThumbnailConfig.WaterMarkTextFoneBorder.ToString( );
            txtWaterMarkTextFoneBorderColor.Value = ThumbnailConfig.WaterMarkTextFoneBorderColor.ToString( );
            DropWaterMarkTextPosition.SelectedValue = ThumbnailConfig.WaterMarkTextPosition.ToString( );
            txtWaterMarketTextPositionX.Text = ThumbnailConfig.WaterMarketTextPositionX.ToString( );
            txtWaterMarketTextPositionY.Text = ThumbnailConfig.WaterMarketTextPositionY.ToString( );
            txtWaterMarkImagePath.Text = ThumbnailConfig.WaterMarkImagePath.ToString( );
            txtWaterMarkPercent.Text = ThumbnailConfig.WaterMarkPercent.ToString( );
            DropWaterMarkPercent.SelectedValue = ThumbnailConfig.WaterMarkCompute.ToString( );
            txtWaterMarkThumbPercent.Text = ThumbnailConfig.WaterMarkThumbPercent.ToString( );
            txtTransparence.Text = ThumbnailConfig.Transparence.ToString( );
            DropWaterMarkImagePosition.SelectedValue = ThumbnailConfig.WaterMarkImagePosition.ToString( );
            txtWaterMarkImagePositionX.Text = ThumbnailConfig.WaterMarkImagePositionX.ToString( );
            txtWaterMarkImagePositionY.Text = ThumbnailConfig.WaterMarkImagePositionY.ToString( );
        }

        protected void BtnSubmit_Click( object sender , EventArgs e )
        {
            int wmt = 0;
            if ( radText.Checked )
            {
                wmt = 0;
            }
            else if ( radImage.Checked )
            {
                wmt = 1;
            }

            bool isSuccess = ThumbnailConfig.Config( txtThumbsWidth.Text.Trim( ) , txtThumbsHeight.Text.Trim( ) , radThumbsMode.SelectedValue.ToString( ) , txtBgColor.Value.Trim( )
            , wmt.ToString( ) , txtWaterMarkText.Text.Trim( ) , ddlWaterMarkTextFoneType.SelectedValue.Trim( ) , DropWaterMarkTextFoneStyle.SelectedValue.ToString( )
            , txtWaterMarkTextFoneSize.Text.Trim( ) , txtWaterMarkTextFoneColor.Value.Trim( ) , txtWaterMarkTextFoneBorder.Text.Trim( ) , txtWaterMarkTextFoneBorderColor.Value.Trim( )
            , DropWaterMarkTextPosition.SelectedValue.ToString( ) , txtWaterMarketTextPositionX.Text.Trim( ) , txtWaterMarketTextPositionY.Text.Trim( ) , txtWaterMarkImagePath.Text.Trim( )
            , txtWaterMarkPercent.Text.Trim( ) , DropWaterMarkPercent.SelectedValue.ToString( ) , txtWaterMarkThumbPercent.Text.Trim( ) , txtTransparence.Text.Trim( )
            , DropWaterMarkImagePosition.SelectedValue.Trim( ) , txtWaterMarkImagePositionX.Text.Trim( ) , txtWaterMarkImagePositionY.Text.Trim( ) );

            if ( isSuccess )
            {
                Response.Redirect( "../../Message.aspx?msg=" + Server.UrlEncode( "缩略图配置成功！" ) + "&rtn=SystemSet/SiteInfo/ThumbnailSet.aspx" );
            }
            else
            {
                Response.Redirect( "../../Message.aspx?msg=" + Server.UrlEncode( "缩略图配置失败，请联系管理员！" ) + "&rtn=SystemSet/SiteInfo/ThumbnailSet.aspx" );
            }
        }
    }
}
